package com.ruoyi.restaurant.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.ruoyi.restaurant.vo.DashboardVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.restaurant.mapper.SysJiagongMapper;
import com.ruoyi.restaurant.domain.SysJiagong;
import com.ruoyi.restaurant.service.ISysJiagongService;

/**
 * 后厨加工情况Service业务层处理
 * 
 * @author ruoyi
 * @date 2022-05-07
 */
@Service
public class SysJiagongServiceImpl implements ISysJiagongService 
{
    @Autowired
    private SysJiagongMapper sysJiagongMapper;

    /**
     * 查询后厨加工情况
     * 
     * @param makeId 后厨加工情况主键
     * @return 后厨加工情况
     */
    @Override
    public SysJiagong selectSysJiagongByMakeId(Integer makeId)
    {
        return sysJiagongMapper.selectSysJiagongByMakeId(makeId);
    }

    /**
     * 查询后厨加工情况列表
     * 
     * @param sysJiagong 后厨加工情况
     * @return 后厨加工情况
     */
    @Override
    public List<SysJiagong> selectSysJiagongList(SysJiagong sysJiagong)
    {
        return sysJiagongMapper.selectSysJiagongList(sysJiagong);
    }

    /**
     * 新增后厨加工情况
     * 
     * @param sysJiagong 后厨加工情况
     * @return 结果
     */
    @Override
    public int insertSysJiagong(SysJiagong sysJiagong)
    {
        return sysJiagongMapper.insertSysJiagong(sysJiagong);
    }

    /**
     * 修改后厨加工情况
     * 
     * @param sysJiagong 后厨加工情况
     * @return 结果
     */
    @Override
    public int updateSysJiagong(SysJiagong sysJiagong)
    {
        return sysJiagongMapper.updateSysJiagong(sysJiagong);
    }

    /**
     * 批量删除后厨加工情况
     * 
     * @param makeIds 需要删除的后厨加工情况主键
     * @return 结果
     */
    @Override
    public int deleteSysJiagongByMakeIds(Integer[] makeIds)
    {
        return sysJiagongMapper.deleteSysJiagongByMakeIds(makeIds);
    }

    /**
     * 删除后厨加工情况信息
     * 
     * @param makeId 后厨加工情况主键
     * @return 结果
     */
    @Override
    public int deleteSysJiagongByMakeId(Integer makeId)
    {
        return sysJiagongMapper.deleteSysJiagongByMakeId(makeId);
    }


    /****
     * 按餐品种类category_names统计餐品售卖数（根据加工情况用category_names统计餐品售卖数）
     * @return 结果
     */
    @Override
    public List<DashboardVo> countByCategoryNames(){
        List<SysJiagong> jiagongList = this.sysJiagongMapper.selectSysJiagongList(new SysJiagong());
        List<DashboardVo> dashboardVoList = new ArrayList<>();
        for(SysJiagong jiagong :jiagongList){
            DashboardVo dashboardVo = new DashboardVo();
            long count = this.sysJiagongMapper.countByCategoryNames(jiagong.getCategoryNames());
            String name = jiagong.getItemNames();
            dashboardVo.setValue(count);
            dashboardVo.setName(name);
            dashboardVoList.add(dashboardVo);
        }

        return dashboardVoList;

    }
}
